<?php
    namespace Home\Controller;
    use Think\Controller;
    class JixiaorenyuanshezhiController extends Controller {
    
    public function _initialize()
    {
        header("Access-Control-Allow-Origin: *");  

        header("Access-Control-Allow-Credentials: true"); 
      
        header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS"); //允许的请求类型
        
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept"); 

    }

    public function get_list()
    {
        $page = I("get.page");
        $limit = I("get.limit");

        $name       = I("get.name");
        $dept_code  = I("get.dept_code");
        $st_date    = I("get.st_date");

        $where = " 1 = 1 ";

        if(!empty($name))
        {
            $where .= " and staff_name like '%$name%'";
        }

        if(!empty($dept_code))
        {
            $where .= " and dept_code = '$dept_code'";
        }

        if(!empty($st_date))
        {
            $st_date = strtotime($st_date);
            $where .= " and st_date = '$st_date'";
        }
        else
        {
            $where .= " and st_date = '0'";
        }

        $data = M("performance.set_checkbonusdays")->where($where)->limit(($page-1)*$limit,$limit)->select();
        for ($i=0; $i < count($data); $i++) 
        { 
            $data[$i]['personsmodulus'] = (float)$data[$i]['personsmodulus'];
        }
        $json["data"] = $data;
        $json["code"] = 0;
        $json["count"] = M("performance.set_checkbonusdays")->where($where)->count();
        $json["msg"] = "";
        
        $this->ajaxReturn($json,"json");
    }

    public function get_one()
    {
        $uuid = I("post.uuid");

        $info = M("performance.set_checkbonusdays")->where("uuid = '$uuid'")->find();
        $info["dept_date"] = date("Y-m-d H:i:s",$info["dept_date"]);
        $json["data"]   = $info;
        $json["code"]   = 0;
        $json["msg"]    = "";

        $this->ajaxReturn($json,"json");
    }

 public function save_one()
    {
        $data = I("post.");

        $where["st_date"] = $data['st_date'];
        $where["dept_code"] = $data['dept_code'];
        $where["user_id"] = $data['user_id'];

        $d['isbonus'] = $data['isbonus'];

        $result = M("performance.set_checkbonusdays")->where($where)->save($d);
        
        if($result !== false)
        {
            $json["code"] = 0;
            $json["msg"] = "修改成功";
        }
        else
        {
            $json["code"] = -1;
            $json["msg"] = "修改失败";
        }
 
        $this->ajaxReturn($json,"json");
    }

    public function add_one()
    {
        $data = I("post.");
        $data["st_date"] = strtotime($data["st_date"]);
        $uuid = uuid();
        
        $result = M("performance.set_checkbonusdays")->add($data);
        
        if($result !== false)
        {
            $json["code"] = 0;
            $json["msg"] = "添加成功";
        }
        else
        {
            $json["code"] = -1;
            $json["msg"] = "添加失败";
        }
 
        $this->ajaxReturn($json,"json");
    }

    public function get_sys_dept_dict()
    {
        // echo 1;
        $data = M("comm.sys_dept_dict")->where("attr = 1")->select();
        for ($i=0; $i < count($data); $i++) 
        { 
            $info = $data[$i];
        }
        $json["data"] = $data;
        $json["code"] = 0;
        $json["count"] =0 ;
        $json["msg"] = "";
        
        $this->ajaxReturn($json,"json");
    }

    public function get_new_staff_info()
    {
        $dept_code    = I("post.dept_code");

        $where = " 1 = 1 ";

        if(!empty($dept_code))
        {
            $where .= " and dept_code = '$dept_code'";
        }
        // echo 1;
        $data = M("rlzy.new_staff_info")->where($where)->select();
        for ($i=0; $i < count($data); $i++) 
        { 
            $info = $data[$i];
        }
        $json["data"] = $data;
        $json["code"] = 0;
        $json["count"] =0 ;
        $json["msg"] = "";
        
        $this->ajaxReturn($json,"json");
    }
    
    public function set_field()
    {
        $data_all = I("post.");

        $days           = $data_all["days"];
        $personsmodulus = $data_all["personsmodulus"];
        $uuid           = $data_all["uuid"];

        $data['days'] = $days;
        $data['personsmodulus'] = $personsmodulus;
        $where['uuid'] = $uuid;

        // var_dump($data);
        // die();

        $result = M("performance.set_checkbonusdays")->where($where)->save($data);

        if($result !== false)
        {
            $json["code"] = 0;
            $json["msg"] = "修改成功";
        }
        else
        {
            $json["code"] = -1;
            $json["msg"] = "修改失败";
        }
        $this->ajaxReturn($json,"json");
    }

}